package com.baidu.navigationdemo.recyclerView

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper
import com.baidu.navigationdemo.R
import com.baidu.navigationdemo.databinding.ActivityNewsBinding

class NewsActivity : AppCompatActivity() {
    private lateinit var binding:ActivityNewsBinding
    @SuppressLint("UseCompatLoadingForDrawables")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityNewsBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        /*
            1. 添加RecyclerView
            2. 定义Adapter  RecyclerView.Adapter
            3. 给RecyclerView对象设置 adapter
            4. 设置布局管理器 LayoutManager
            4. 设置RecyclerView的显示方向 纵向和横向
         */
        val data = listOf(
            News(R.drawable.icon_home, "Android","我爱Android开发"),
            News(R.drawable.icon_videocam_, "iOS","我爱iOS开发"),
            News(R.drawable.icon_videocam_, "Web前端开发","我爱Web前端开发"),
            News(R.drawable.icon_home, "Android","我爱Android开发"),
            News(R.drawable.icon_videocam_, "iOS","我爱iOS开发"),
            News(R.drawable.icon_videocam_, "Web前端开发","我爱Web前端开发"),
            News(R.drawable.icon_home, "Android","我爱Android开发"),
            News(R.drawable.icon_videocam_, "iOS","我爱iOS开发"),
            News(R.drawable.icon_videocam_, "Web前端开发","我爱Web前端开发"),
            News(R.drawable.icon_home, "Android","我爱Android开发"),
            News(R.drawable.icon_videocam_, "iOS","我爱iOS开发"),
            News(R.drawable.icon_videocam_, "Web前端开发","我爱Web前端开发"),
            News(R.drawable.icon_home, "Android","我爱Android开发"),
            News(R.drawable.icon_videocam_, "iOS","我爱iOS开发"),
            News(R.drawable.icon_videocam_, "Web前端开发","我爱Web前端开发"),
            News(R.drawable.icon_home, "Android","我爱Android开发"),
            News(R.drawable.icon_videocam_, "iOS","我爱iOS开发"),
            News(R.drawable.icon_videocam_, "Web前端开发","我爱Web前端开发"),
        )
        val mAdapter = MyAdapter()
        mAdapter.setData(data)
        binding.recyclerView.adapter = mAdapter
        binding.recyclerView.layoutManager = LinearLayoutManager(
            this, LinearLayoutManager.VERTICAL, false
        )
        //设置按页显示
        PagerSnapHelper().attachToRecyclerView(binding.recyclerView)
    }
}